package com.example.su_shi_tan_mine.child

import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.appcompat.widget.Toolbar
import com.alibaba.fastjson.JSON
import com.example.library_common.utils.normalShortToast
import com.example.su_shi_tan_bas_lib.adapter.JssBaseViewHolder
import com.example.su_shi_tan_bas_lib.base.BaseFragmentEx
import com.example.su_shi_tan_bas_lib.base.LazyFragment
import com.example.su_shi_tan_bas_lib.base.SimpleListFragment
import com.example.su_shi_tan_bas_lib.bean.CommonBean
import com.example.su_shi_tan_bas_lib.networking.RestClient
import com.example.su_shi_tan_mine.R
import com.example.su_shi_tan_mine.child.bean.MessagePageBean
import com.example.su_shi_tan_mine.child.bean.SharePostFansBean
import ikidou.reflect.TypeBuilder
import java.lang.reflect.Type

class SharePostFansFragment : SimpleListFragment<SharePostFansBean>(), SharePostLabel {

    override fun labelInfo() = "推广粉丝"

    companion object {
        fun newInstance(): SharePostFansFragment {
            val args = Bundle()
            val fragment = SharePostFansFragment()
            fragment.arguments = args
            return fragment
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mSuperBackPressedSupport=false
    }

//    override fun initView(view: View) {
//        super.initView(view)
//        mHeader.removeAllViews()
//        addHeader(R.layout.comment_header_layout)
//        val mToolbar: Toolbar =mHeader.findViewById(R.id.mToolbar)
//        mToolbar.title="公告"
//        mToolbar.setNavigationOnClickListener { onBackPressedSupport() }
//    }

    override fun getItemLayout(): Int {
        return R.layout.share_post_fans_fragment
    }

    override fun convertItem(helper: JssBaseViewHolder?, item: SharePostFansBean?) {

    }

    override fun getListType(): Type {
        return TypeBuilder.newInstance(CommonBean::class.java)
            .beginSubType(List::class.java)
            .addTypeParam(SharePostFansBean::class.java).endSubType().build()
    }

    override fun netRequest() {
        RestClient.builder()
            .url(R.string.spread_people)
            .raw(
                JSON.toJSONString(
                    mapOf(
                        "limit" to "10",
                        "sort" to "",
                        "page" to pageIndex,
                        "grade" to "0",
                        "keyword" to "",
                    )
                )
            )
            .success {
                parseDate(it)
            }
            .error { _, _ ->
              onFailed()
            }.failure {
                onFailed()
            }
            .build()
            .post()
    }

    override fun parseDate(data: String?) {
//        super.parseDate(data)
        val obj = JSON.parseObject(data)
        val mArray = JSON.parseArray(obj["list"].toString(), SharePostFansBean::class.java)
        loadListDate(mArray)
    }


}